define(
    ["PDUtilDir/grid", "PDUtilDir/dataService", "PDUtilDir/util",
        "AppPathDir/finance/productFinanceInfos/order", "PDUtilDir/searchBlock",
        "AppPathDir/finance/productFinanceInfos/detail",
        "Date", "DateCN", "css!DateCss"],
    function (Grid, DataService, Util, OrderSupport, SearchBlock, DetailSupport) {
        HomeApp.controller('BodyCtrl', ["$scope", "$compile", '$sce', function ($scope, $compile, $sce) {
            $scope.entity = {
                product: DataService.getObject('product.object')
            };
            $scope.search = {};
            $scope.cache = {};

            // SearchBlock.init('searchBlockIdForTimetable');

            //出发日期初始化
            $("#dateSearch").datetimepicker({
                // 设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
                language: "cn",
                // 输出格式化
                // format : 'yyyy-mm-dd hh:ii:ss',
                format: 'yyyy-mm-dd',
                // 直接选择‘今天’
                todayBtn: true,
                // 设置最精确的时间选择视图
                minView: 'month',
                // 高亮当天日期
                todayHighlight: true,
                // 显示“上午”“下午”
                showMeridian: true,
                // 选择完毕后自动关闭
                autoclose: true
            });

            // 订单列表
            $scope.orderSupport = OrderSupport($scope, $compile);

            $scope.detailSupport = new DetailSupport($scope, $compile);

            $scope.searchSupport = {
                run: function () {
                    $scope.grid.reload({
                        queryParam: {
                            model: JSON.stringify($scope.search)
                        }
                    })
                }
            };
            // SearchBlock.init('searchBlockIdForTimetable');
            $scope.grid = Grid({
                id: "ProductFinanceTimtableGirdDivId",
                pageSize: 10,
                multi: true,
                pagination: true,
                cache: false,
                layout: [{
                    name: "时间",
                    field: "date",
                    width: '100px',
                    sort: true,
                    format: function (e) {
                        return e.row.date.replace("00:00:00", "");
                    },
                    click: function (e) {
                        $scope.updateSupport.run(e.data.row);
                    }
                }, {
                    name: "数量",
                    field: "personNum",
                    width: '40px'
                }, {
                    name: "余量",
                    field: "restPersonNum",
                    width: '40px'
                }, {
                    name: "销售人数",
                    field: "totalSaledPerson",
                    width: '80px'
                }, {
                    name: "成人成本",
                    field: "costPrice",
                    width: '80px',
                    click: function (e) {
                        $scope.updateSupport.run(e.data.row);
                    }
                }, {
                    name: "成人价格",
                    width: '80px',
                    field: "salePriceAdult"
                }, {
                    name: "儿童成本",
                    width: '80px',
                    field: "costPriceChild"
                }, {
                    name: "儿童价格",
                    width: '80px',
                    field: "salePriceChild"
                }, {
                    name: "其他成本",
                    width: '80px',
                    field: "costPriceOther"
                }, {
                    name: "其他价格",
                    width: '80px',
                    field: "salePriceOther"
                }/*, {
                    name: "创建人",
                    field: "createUserName"
                }*/, {
                    name: "创建时间",
                    width: '140px',
                    field: "createTime"
                }, {
                    name: "操作",
                    field: "id",
                    width: '120px',
                    format: function (e) {
                        return '<a href="javascript:angular.element(\'#ProductFinanceTimtableGirdDivId\').scope().orderSupport.run(\'' + e.row.id + '\')">订单列表</a>'
                            + '<a href="javascript:angular.element(\'#ProductFinanceTimtableGirdDivId\').scope().detailSupport.run(\'' + e.row.id + '\')">明细</a>';
                    }
                }],
                toolbar: [{
                    name: "查询",
                    icon: "fa fa-search",
                    callback: function (event) {
                        $scope.searchSupport.run();
                    }
                }],
                data: {
                    type: 'URL',
                    value: getServer()
                    + '/flea/hclv/calFinance/auidtByProductId.htmls?model=' + $scope.entity.product.id
                }
            });
        }
        ]);
    });